library(ggplot2)

dfmg<-read.csv("1L2_Mg_titration.csv")

#create line plot
ggplot(dfmg, aes(x=Concentration, y=Mean_RelativeActivity, color = Sample, group = Sample)) +
  geom_line(size=0.6, show.legend = F)+
  geom_point(aes(shape=Sample, color=Sample), size=3, show.legend = T)+
  scale_color_manual(values= c("forestgreen", "turquoise1", "lightseagreen"), labels=c(expression(paste("0"~"mM"~"Ca"^"2+")), expression(paste("1"~"mM"~"Ca"^"2+")), expression(paste("3"~"mM"~"Ca"^"2+"))))+
  scale_shape_manual(values=c(9,7,8), labels=c(expression(paste("0"~"mM"~"Ca"^"2+")), expression(paste("1"~"mM"~"Ca"^"2+")), expression(paste("3"~"mM"~"Ca"^"2+"))))+
  geom_errorbar(data = dfmg, aes(ymin=Mean_RelativeActivity-StDev, ymax=Mean_RelativeActivity+StDev), width=0.2) +
  theme_minimal() +
  labs(
    title = "Divalent cations titration",
    x = expression(paste("[Mg"^"2+"*"]"~"(mM)")),
    y = "Relative DNase activity (%)"
  )+
  theme(axis.text.x = element_text(size = 16), axis.text.y = element_text(size = 16), 
        axis.title.y = element_text(size=20), axis.title.x = element_text(size=20), 
        title = element_text(size = 16), 
        legend.title = element_blank(), legend.text = element_text(size=16), 
        legend.position = c(0.7, 0.58), legend.key.height = unit(0.75, "cm"), 
        plot.margin = margin(0.5, 0.5, 0.5, 0.5, "cm"))

ggsave("Mg_titration.pdf", width = 17, height = 15, units = "cm")
